﻿using BLL;
using Model;
using System;
using System.Data;
using System.Web.UI.WebControls;
using Utility.Helper;

namespace Thksoft.UserCotrols
{
    public partial class CtrlYearFundsMX : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string busId = Request.QueryString["N_business_id"].ToString();

                hidId.Value = busId;
                //  ViewState["busId"] = busId.ToString();
                BindDt(busId);
            }
        }

        #region 旧代码

        ///// <summary>
        ///// 绑定数据
        ///// </summary>
        //public void BindDt(string busId)
        //{
        //    QS_Business bModel = new Qs_BusinessBLL().GetBusinessById(Decimal.Parse(busId));

        //    lblTime.Text = bModel.Business_operator_date.ToShortDateString();

        //    lblUser.Text = new Sys_UserBLL().GetInfoById(bModel.Business_operator_Id.ToString()).USER_NAME;

        //    string sql = string.Format(@" select * from qx_planyearapply t where t.n_business_id=" + busId);

        //    DataTable dtYear = new BaseBLL().Query(sql);

        //    if (dtYear == null || dtYear.Rows.Count < 1)
        //    {
        //        Response.Write("<script>alert('【系统提示】该条数据有误，请与管理员联系');location.href='../Right.aspx';</script>");
        //        return;
        //    }

        //    lblyear.Text = dtYear.Rows[0]["N_YEAR"].ToString();

        //    lblBzyj.Text = dtYear.Rows[0]["C_REAMRK"].ToString();

        //    lbldw.Text = new Sys_CompanyBLL().GetInfoById(dtYear.Rows[0]["N_COMPANY_ID"].ToString()).CMY_NAME;

        //    this.hidId.Value = dtYear.Rows[0]["N_YEARAPP_ID"].ToString() + "@" + busId;

        //    DataTable dt = new QX_PLANYEARAPPLYBLL().GetDataBind(busId);

        //    gvMonthFunds.DataSource = dt;

        //    gvMonthFunds.DataBind();
        //}

        //protected void gvMonthFunds_RowDataBound(object sender, GridViewRowEventArgs e)
        //{
        //    if (e.Row.RowType == DataControlRowType.DataRow)
        //    {
        //        string type = ((Label)e.Row.FindControl("lbltype")).Text;
        //        if (type == "0")
        //        {
        //            e.Row.Attributes["style"] = "background-color:#B2D8FF;font-size: 14px";

        //            // e.Row.Cells[2].Attributes["style"] = "font-size: 14px";
        //        }
        //        else if (type == "1")
        //        {
        //            e.Row.Attributes["style"] = "background-color:#CCCCCC;font-size: 13px;";

        //            //  e.Row.Cells[2].Attributes["style"] = "font-size: 13px";
        //        }

        //    }
        //}

        #endregion 旧代码

        #region 新代码

        public void BindDt(string busId)
        {
            QS_Business bModel = new Qs_BusinessBLL().GetBusinessById(Decimal.Parse(busId));

            lblTime.Text = bModel.Business_operator_date.DateFormat("yyyy-MM-dd");

            lblUser.Text = new Sys_UserBLL().GetInfoById(bModel.Business_operator_Id.ToString()).USER_NAME;

            string sql = string.Format(@" select * from qx_planyearapply t where t.n_business_id=" + busId);

            DataTable dtYear = new BaseBLL().Query(sql);

            if (dtYear == null || dtYear.Rows.Count < 1)
            {
                Response.Write("<script>alert('【系统提示】该条数据有误，请与管理员联系');location.href='../Right.aspx';</script>");
                return;
            }

            lblyear.Text = dtYear.Rows[0]["N_YEAR"].ToString();

            lblBzyj.Text = dtYear.Rows[0]["C_REAMRK"].ToString();

            lbldw.Text = new Sys_CompanyBLL().GetInfoById(dtYear.Rows[0]["N_COMPANY_ID"].ToString()).CMY_NAME;

            this.hidId.Value = dtYear.Rows[0]["N_YEARAPP_ID"].ToString() + "@" + busId;

            DataTable dt = new QX_PLANYEARAPPLYBLL().GetDataBind(busId);

            gvMonthFunds.DataSource = dt;

            gvMonthFunds.DataBind();
        }

        protected void gvMonthFunds_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string type = ((Label)e.Row.FindControl("lbltype")).Text;
                if (type == "0")
                {
                    e.Row.Attributes["style"] = "background-color:#B2D8FF;font-size: 14px";

                    // e.Row.Cells[2].Attributes["style"] = "font-size: 14px";
                }
                else if (type == "1")
                {
                    e.Row.Attributes["style"] = "background-color:#CCCCCC;font-size: 13px;";

                    //  e.Row.Cells[2].Attributes["style"] = "font-size: 13px";
                }
            }
        }

        #endregion 新代码
    }
}